<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户--添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/components/treetable-lay/assets/layui/css/layui.css">


    <script src="/manage/js/app.js"></script>
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">


    <div class="layui-form-item">
        <label class="layui-form-label">字典名称</label>
        <div class="layui-input-inline">
            <input type="text" id="name" name="name" lay-verify="required" placeholder="请输入字典名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">字典类型</label>
        <div class="layui-input-inline">
            <input type="text" id="code" name="code" lay-verify="required" placeholder="请尽量使用英文-用于搜索使用" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">字典描叙</label>
        <div class="layui-input-inline">
            <input type="text" id="desc" name="desc" lay-verify="required" value="-" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
            <input type="text" id="sort" name="sort" lay-verify="required" value="0" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>

<script>

    //父Id，如果没有父级设置为0
    let pid = 0;

    layui.use(['form'], function () {
        init();
        formSubmit();
    });


    function init() {
        if (parent.data.lv === 1) {
            //添加类型
        } else if (parent.data.lv === 2) {
            //添加子类别
            pid = parent.data.id;
        }
    }

    function formSubmit() {
        //监听提交
        layui.form.on('submit(layuiadmin-app-form-submit)', function (data) {
            data.field.pid = pid;
            let result = Ajax.post(parent.dictionaryUrl, data.field);
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            parent.layer.msg(result.msg);
            // 重载页面--不建议开启--建议使用手动刷新
            // parent.window.location.reload();
            WindowPos.onbeforeunload();  // 记录滚动条位置
            parent.xijiaRenderTable();
            WindowPos.onload();          // 还原滚动条位置
            layer.msg(result.msg);
            // parent.layer.msg(result.msg + " 请手动刷新");
        });
    }

</script>
</body>
</html>
